# encoding=utf8

"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import os
from resource_management import *
import ast
import socket
from resource_management.libraries.script.script import Script
import commands


def fix_dir(dir_param):
    dir_path = dir_param
    f_dir_path = '/' + dir_path.strip('/') + '/'
    return f_dir_path



config = Script.get_config()

app_name = 'griffin'

# 源码包下载地址
griffin_download_url = config['configurations']['griffin-ambari-config']['griffin.package.download.url']




# 解决stack_root、tmp_dir

hostname = config['agentLevelParams']['hostname']  # 获取agent层面的参数,agent的hostname
ambari_server_host = config['ambariLevelParams']['ambari_server_host']  # 获取ambari层面的参数,ambari_server的host

# HDP配置信息
hdp_stack_root = fix_dir(Script.get_stack_root())
hdp_version = commands.getoutput('hdp-select -v')
hdp_base_dir = fix_dir(os.path.join(hdp_stack_root, hdp_version))

# griffin用户与组信息
griffin_user = config['configurations']['griffin-env']['griffin_user']
griffin_group = config['configurations']['griffin-env']['griffin_group']

# griffin目录信息
griffin_base_dir = fix_dir(hdp_base_dir) + 'griffin'
griffin_service_base_dir = fix_dir(griffin_base_dir) + 'griffin-service'
griffin_pid_dir = config['configurations']['griffin-env']['griffin_pid_dir']
griffin_log_dir = (config['configurations']['griffin-env']['griffin_log_dir']).rstrip('/')
griffin_bin_dir = fix_dir(griffin_service_base_dir) + '''bin/'''
griffin_conf_dir = fix_dir(griffin_service_base_dir) + '''config/'''
griffin_sh_path = fix_dir(griffin_bin_dir) + 'griffin.sh'
griffin_pid_file = fix_dir(griffin_pid_dir) + 'service.pid'


application_properties = {}
application_properties.update(config['configurations']['griffin-application'])
spark_properties_json = config['configurations']['griffin-sparkProperties']['sparkProperties.json']
env_batch_json = config['configurations']['griffin-sparkProperties']['env_batch.json']
env_streaming_json = config['configurations']['griffin-sparkProperties']['env_streaming.json']

